package com.mrlv.api.utils;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.mrlv.api.enums.ResultStatusEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * @author MrLv
 * @version 1.0
 * @description: TODO
 * @date 2021/6/16 13:52
 */
@Data
@AllArgsConstructor
@Accessors(chain = true)
@ApiModel(description="通用响应返回对象")
public class ResultMsg<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "状态码")
    private int code;

    @ApiModelProperty(value = "描述信息")
    private String msg;

    @ApiModelProperty(value = "返回数据")
    private T data;

    public ResultMsg(ResultStatusEnum status, T data)  {
        //String i18nMsg = LocaleUtils.getMessage(status.name());
        this.code = status.getCode();
//        this.msg = StringUtils.isNotBlank(i18nMsg) ? i18nMsg : status.getMsg();
        this.msg = status.getMsg();
        this.data = data;
    }

    public static <T>ResultMsg<T> createBySuccess(){
        return new ResultMsg<T>(ResultStatusEnum.OK.getCode(), null, null);
    }

    public static <T>ResultMsg<T> createBySuccessMessage(String msg){
        return new ResultMsg<T>(ResultStatusEnum.OK.getCode(), msg, null);
    }

    public static <T> ResultMsg<T> createBySuccess(T data){
        return new ResultMsg<T>(ResultStatusEnum.OK.getCode(), null, data);
    }

    public static <T> ResultMsg<T> createResult(ResultStatusEnum status, T data){
        return new ResultMsg<T>(status, data);
    }
    public static <T> ResultMsg<T> createResult(int code, String message, T data){
        return new ResultMsg<T>(code, message, data);
    }
    public static <T> ResultMsg<T> createResult(int code,  T data){
        return new ResultMsg<T>(code, null, data);
    }
    public static <T> ResultMsg<T> createResult(ResultStatusEnum status){
        return new ResultMsg<T>(status, null);
    }

    public static <T> ResultMsg<T> createBySuccess(String msg, T data){
        return new ResultMsg<T>(ResultStatusEnum.OK.getCode(), msg, data);
    }

    public static <T> ResultMsg<T> createByError(){
        return new ResultMsg<T>(ResultStatusEnum.SYSTEM_ERR.getCode(), ResultStatusEnum.SYSTEM_ERR.getMsg(), null);
    }

    public static <T>ResultMsg<T> createByErrorMessage(String errorMessage){
        return new ResultMsg<T>(ResultStatusEnum.SYSTEM_ERR.getCode(), errorMessage, null);
    }

    public static <T>ResultMsg<T> createByErrorCodeMessage(int errorCode, String errorMessage){
        return new ResultMsg<T>(errorCode, errorMessage, null);
    }
    public static <T>ResultMsg<T> createByErrorCodeMessageData(int errorCode, String errorMessage, T data){
        return new ResultMsg<T>(errorCode, errorMessage, data);
    }
}